package cn.fastoo.web.backstage.web.controller.sales;

import cn.fastoo.common.dao.base.BaseMeasurementDao;
import cn.fastoo.common.dao.sales.goals.SalesGoalsDao;
import cn.fastoo.common.entity.base.BaseMeasurement;
import cn.fastoo.common.entity.sales.goals.SalesGoals;
import cn.fastoo.common.sampleframe.dto.JsonResult;
import cn.fastoo.common.sampleframe.search.QuerySearch;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Created by lowkey on 17/10/11.
 */
@Controller
@RequestMapping("/sales/goals")
public class SalesGoalsController {

    @Autowired
    private SalesGoalsDao dao;

    @RequestMapping
    public String index() {
        return "/sales/goals/index";
    }



    @RequestMapping("/manager")
    @ResponseBody
    public String manager(@ModelAttribute SalesGoals newData, QuerySearch querySearch, String op) {
         
        if(StringUtils.isNotBlank(op)){
            if("add".equals(op)){
                dao.insert(newData);
                //logger.info(loginUser, SystemLog.TYPE_AUTH_ROLE_ADD,String.format("用户角色[%s]",authRole.getRoleName()));
            }else {
                SalesGoals oldData = dao.findById(newData.getId());
                if(oldData==null){
                    return JsonResult.success("错误参数,请检查");
                }
                if("save".equals(op)){
                    dao.update(newData);
                }else if("del".equals(op)){
                    dao.delete(oldData);
                }
            }
            return JsonResult.success("操作成功");
        }
        return JsonResult.querySearchSuccess(dao.find(querySearch.getSearch()),querySearch);
    }



}
